package com.atguigu.practice;

public class BinarySearch {
    public static int binarySearch(int[] arr,int key,int left,int right){
        if(left>right){
            System.out.println("没找到");
            return -1;
        }
        int mid=left+((right-left)>>1);
        if(arr[mid]>key){
            return binarySearch(arr,key,left,mid-1);
        }else if(arr[mid]<key){
            return binarySearch(arr,key,mid+1,right);
        }else{
            return mid;
        }
    }
    public static void main(String[] args) {
        int[] arr=new int[]{1,5,9,10,33,40,45,77,85,93};
        System.out.println(binarySearch(arr,30,0,arr.length-1));

    }
}
